import time
from selenium import webdriver

def web_dri(proxies):
    options = webdriver.ChromeOptions()
    options.add_argument('--proxy-server='+proxies)
    driver = webdriver.Chrome(executable_path='D:\code\刷票\chromedriver.exe',chrome_options=options)
    url = "http://vote.e23.cn/zhuanti/jnncp2020shibao/show_1.html?openid=&openidMd5=&subscribe=undefined&group=1"
    driver.get(url)
    driver.execute_script('window.scrollTo(0,1000)')   #滑到1000的位置
    # time.sleep(2)
    driver.find_element_by_xpath('//*[@id="searchContent"]').send_keys('128')
    driver.find_element_by_id('searchBtn').click()
    time.sleep(2)
    driver.find_element_by_xpath('//*[@value="128"]').click()
    driver.find_element_by_xpath('//*[@id="form1"]/div[4]/div/div[2]').click()
    time.sleep(2)
    # current_windows = driver.window_handles
    try:
        driver.find_element_by_xpath('//*[@id="layui-layer1"]/div[3]/a').click()
        time.sleep(2)
    except Exception as e:
        print(e)


# IP代理
def proxie():
    proxyHost = "tps131.kdlapi.com"
    proxyPort = "15818"

    # 代理隧道验证信息
    proxyUser = "t18779592125934"
    proxyPass = "ocxzglaw"

    proxyMeta = "http://%(user)s:%(pass)s@%(host)s:%(port)s" % {
        "host": proxyHost,
        "port": proxyPort,
        "user": proxyUser,
        "pass": proxyPass,
    }

    proxies = {
        "http": proxyMeta,
        "https": proxyMeta,
    }
    return proxies['http']


if __name__ == '__main__':
    while True:
        IP_pro = proxie()
        web_dri(IP_pro)